<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<%@ include file="/common-app/taglibs.jsp"%>
<!DOCTYPE html>
<html>
<head>
<title>所有申请书查询</title>
<script type="text/javascript" src="${res}/js/proposal/irisPrpPrepare.js"></script>
<script type="text/javascript" src="${res_app}/js/app/proposal/irisPrpPrepare.js"></script>
</head>

<body>
	<input type="hidden" id="childDiv" class="thickbox" />
	<form method="post" id="mainForm">
			<input type="hidden" id="prpCodes" name="prpCodes" value="" />
			<input type="hidden" id="type" name="type" value="" />
		</form>

	<div class="soBox">
		<div class="detail ico_search">
			
			
			
				<table>
					<tr>
					<td align="right" style="width:128px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;项目类别：</td>
					<td >
					<security:authorize ifNotGranted="A_AUTH_DW,A_AUTH_DEPT,A_AUTH_TJBM">
		            <c:set var="grant">{'id':'${grantCode}','name':'${grantCname}'}</c:set>
						<input name="grantCname_hideId" type="hidden"  id="grantCname_hideId"  value="${grantCode}" >
						<input name="grantCname" type="hidden"  id="grantCname"  value="${grantCname}" >
						<cpt:tree id="grant" width="125px;"   key="evgrant_code_tree" name="grant" value="${grant}" className="input_text_select"  onClick="initSubjectTreeValueExp2"  sqlParamVal="{psn_code:${psnCode},role_id:${roleId}}"  checkable="false" readonly="true" label="业务类别" ></cpt:tree>
						<input name="grant_code" type="hidden"  id="grant_code"  value="${grant_code}" >	
            	</security:authorize>
            	<security:authorize ifAnyGranted="A_AUTH_DW,A_AUTH_DEPT,A_AUTH_TJBM">
           			<c:set var="grant">{'id':'${grantCode}','name':'${grantCname}'}</c:set>
						<input name="grantCname_hideId" type="hidden"  id="grantCname_hideId"  value="${grantCode}" >
						<input name="grantCname" type="hidden"  id="grantCname"  value="${grantCname}" >
						<cpt:tree id="grant" width="125px;"   key="grant_code_tree" name="grant" value="${grant}" className="input_text_select"  onClick="initSubjectTreeValueExp2"  sqlParamVal="{psn_code:${psnCode},role_id:${roleId}}"  checkable="false" readonly="true" label="业务类别" ></cpt:tree>
						<input name="grant_code" type="hidden"  id="grant_code"  value="${grant_code}" >	
            	</security:authorize>
	            </td>
					<td align="left"  style="width:85px;">&nbsp;&nbsp;技术领域：</td>
					<td>
					   &nbsp;&nbsp;&nbsp;&nbsp;<c:set var="research">{'id':'${research_value}','name':'${researchName}'}</c:set>
						<input name="researchCname_hideId" type="hidden"  id="researchCname_hideId"  value="${research_value}" >
						<input name="researchCname" type="hidden"  id="researchCname"  value="${researchName}" >
						<cpt:tree id="research"  width="108px;" key="subject_researcharea_cri" name="research" value="${research}" className="input_text_select" onClick="initSubjectTreeValueExp"   checkable="false" readonly="true" label="技术领域" ></cpt:tree>
						<input name="research_value" type="hidden"  id="research_value"  value="${research_value}" >	
					</td>
					<td align="left"  style="width:60px;">专题名称：</td>
					<td align="left">
						<c:set var="domain">{'id':'${domain_value}','name':'${domainName}'}</c:set>
						<input name="domainCname_hideId" type="hidden"  id="domainCname_hideId"  value="${domain_value}" >
						<input name="domainCname" type="hidden"  id="domainCname"  value="${domainName}" >
						<cpt:tree id="domain" width="127px;" key="domain1" name="domain" value="${domain}" className="input_text_select" onClick="initSubjectTreeValueExp"  sqlParamVal="" checkable="false" readonly="true" label="专题名称" ></cpt:tree>
						<input name="domain_value" type="hidden"  id="domain_value"  value="${domain_value}" >	
					</td>
					</tr>
					<tr><td style="height:11px;"></td></tr>
				</table>
			
			<table>
				<tr>
					<td rowspan="2"><strong>检索条件：</strong>
					</td>
						<security:authorize ifNotGranted="A_AUTH_DW,A_AUTH_DEPT,A_AUTH_TJBM">
					<td>
						<cpt:search key="prpApprove_search2_chushi"  repeatColumn="3" displayCount="6" leftStyle="width:80px"></cpt:search>
					</td>
					</security:authorize>
					<security:authorize ifAnyGranted="A_AUTH_DW,A_AUTH_DEPT,A_AUTH_TJBM">
					<td>
					 <cpt:search key="prpApprove_search2"  repeatColumn="3" displayCount="6" leftStyle="width:80px"></cpt:search>
					</td>
					</security:authorize>
					
				</tr>
				<tr>
				<td>
					<div class="clear_h10"></div>
					<input type='button' id='searchBt' class="button_an" value='查询' />
				</td>
				</tr>
			</table>
		</div>
	</div>
	<div class="clear_h10"></div>
	<div>
		<div id='TopBarMnt'></div>
		<table id='dataGrid'></table>
		<div id='dataBar'></div>
	</div>
  <iframe id="ifile" style="display:none"></iframe>
	<form action="${ctx}/prpapprove/export_excel" method="post" id="exportExcel">
		<input type="hidden" name="searchString" id="searchString" value="" />
		<input type="hidden" name="sidx" id="sortItem" value="" />
		<input type="hidden" name="sord" id="sortType" value="" />
		<input name="grantCnameKJ" type="hidden"  id="grantCnameKJ"   >
	</form>
	<%-- <form action="${ctx}/prpapprove/export_excel_collects" method="post" id="exportPrjCollects">
		<input type="hidden" name="searchString" id="searchString" value="" />
		<input type="hidden" name="sidx" id="sortItem" value="" />
		<input type="hidden" name="sord" id="sortType" value="" />
		<input name="grantCnameKJ" type="hidden"  id="grantCnameKJ"   >
	</form> --%>
	<script type="text/javascript">
	var irisGrid = new IrisGrid("dataGrid", "dataBar", 'TopBarMnt');
	var prcWin = new progressWin("${res}");//初始化遮罩层
	
	var getSelOptPrpCode = function() {
        var g = "";
        $("input:checkbox[id^=jqg_dataGrid_]").each(function(i, obj) {
            
            if (obj.checked) {
            	
            	var prpCode = $(obj).parents("tr").find("input[id^=prpCode_]").attr("id").replace("prpCode_", "");
                if(prpCode == "") {
                       return;
                }
                g += "," + prpCode;            }
        });
        if (g != "") {
            g = g.substring(1);
        }
        return g;
    };
    
    function sendMessage(type, gridObj, selectIdArray, recordRows) {
    	var prpCodes = getSelOptPrpCode();
        if (recordRows == '') {
            prpCodes = selectIdArray + '';
        }
        if (prpCodes == "") {
            scmError("请选择一条非填写中记录");
            return false;
        }
        if (type == "noticeSms") {
            var prpnum = prpCodes.split(",").length;
            var isNotice = "1";

            if (confirm("是否确认短信通知此" + prpnum + "份申报书的项目负责人和单位联系人?")) {

                var options = {
                    type : 'post',
                    data : {
                        "prpCodes" : prpCodes,
                        "isNotice" : isNotice,
                        "isSendSms":"true"
                    },
                    beforeSend : function() {
                    }, // 表单提交前的回调函数
                    success : function(msg) {
                        if(msg=="success"){
                            try {
                                scmSuccess("操作成功！");
                                prcWin.closeWin();
                                irisGrid.getGridDom().jqGrid("refresh", 1);//0是本页1是首页
                            } catch (e) {
                            }
                        }
                        else{
                            scmSuccess(msg);
                        }
                    },// 表单成功提交后的回调函数
                    error : function() {
                        scmError("操作失败！");
                        prcWin.closeWin();
                    },
                    url : "${ctx}/prpapprove/sentEmailNotice?smsCode=${smsTmpCode}&smsCustomCode=${smsCustomTmpCode}"
                };
                $.ajax(options);

            }
        }else if (type == "noticeEmail") {
            var prpnum = prpCodes.split(",").length;
            var isNotice = "1";

            if (confirm("是否确认邮件通知此" + prpnum + "份申报书的项目负责人和单位联系人及项目联系人?")) {

                var options = {
                    type : 'post',
                    data : {
                        "prpCodes" : prpCodes,
                        "isNotice" : isNotice,
                        "isSendMail":"true"
                    },
                    beforeSend : function() {
                    }, // 表单提交前的回调函数
                    success : function(msg) {
                        if(msg=="success"){
                            try {
                                scmSuccess("操作成功！");
                                prcWin.closeWin();
                                irisGrid.getGridDom().jqGrid("refresh", 1);//0是本页1是首页
                            } catch (e) {
                            }
                        }
                        else{
                            scmSuccess(msg);
                        }
                    },// 表单成功提交后的回调函数
                    error : function() {
                        scmError("操作失败！");
                        prcWin.closeWin();
                    },
                    url : "${ctx}/prpapprove/sentEmailNotice?mailCode=${mailTmpCode}&mailCustomCode=${mailCustomTmpCode}"
                };
                $.ajax(options);

            }
        }

        else {
            return;
        }
    }
    
	function showApproveDialog(type){
        var prpCodes = getSelOpt();
		
		if(prpCodes==""){
			scmError("请选择一条记录");
			return false;
		}
		if(type=="approve"){
				
				var prpnum = prpCodes.split(",").length-1;
				$("#prpCodes").val(prpCodes);
				$("#type").val(type);
				var options = {
						beforeSubmit : function() {
							prcWin.openWin();//打开遮罩层
							$("#approve").attr("disabled",true);
						}, // 表单提交前的回调函数
						success : function(msg) {
							prcWin.closeWin();
							scmSuccess(msg);
							irisGrid.getGridDom().jqGrid("refresh",0);//0是本页1是首页
							$("#approve").attr("disabled",false);
						},// 表单成功提交后的回调函数
						error : function() {
							scmError("操作失败,请联系系统管理员");
							prcWin.closeWin();
							$("#approve").attr("disabled",false);
						},
						url: "${ctx}/prpapprove/"+type
					};
				if(confirm("是否确认此"+prpnum+"份申请书?")){
					$("#mainForm").ajaxSubmit(options);
				}
				else{
					return;
				}
			
		}
		else{
			var url="${ctx}/prpapprove/openprpapprovedialog?prpCodes="+prpCodes+"&type="+type+"&TB_iframe=true&height=220&width=400";
			var title="申报审核意见（最多为500字）";
			showThickBox(url,title);
		}
		
	}
	
	function checkSelect(){
		var selectArray=irisGrid.getGridDom().jqGrid("getGridParam", 'selarrrow');//获得选中行
		$("#approve").removeAttr("disabled");//去除该属性
		for(var i=0;i<selectArray.length;i++){
			var status=irisGrid.getGridDom().jqGrid('getCell',selectArray[i],"13");
			var flagCan=irisGrid.getGridDom().jqGrid('getCell',selectArray[i],"14");
			if(status=='01'&&flagCan=="0") {
				$("#approve").attr("disabled","disabled");
				scmError("您所选择的这"+selectArray.length+"份申请书中有部分申请书的正式PDF未生成，请在生成之后再选择该申请书进行确认操作");
			}
		}
	}
	
	function viewComment(des3Prpcode){
		var url="${ctx}/proposal/view/audit-comment-view?posCode="+des3Prpcode+"&TB_iframe=true&height=390&width=720";
		var title="审核意见";
		showThickBox(url,title);	
	}
	
	function closeDialog(){
		tb_remove();
	}
    var editSms = function() {
        var url = "${ctx}/sms/update-smstmp?smsCode=${smsTmpCode}&smsCustomCode=${smsCustomTmpCode}&type=${smsTemplateType}&TB_iframe=true&height=360&width=500";
        tb_show("修改短信通知模板", url, false);
    };
    var editEmail  = function() {
        var url = "${ctx}/mail/update-mailtmp?sourceTmpCodeStr=${mailTmpCode}&tmpCodeStr=${mailCustomTmpCode}&TB_iframe=true&height=360&width=700";
        tb_show("修改邮件通知模板", url, false);
    };
	
		/** 表格初始化**/
		//loadIrisGrid("${res}");
		function buildGrid() {
			var columnAttrList = new Array();
			columnAttr = new ColumnAttr("项目类别", "grant_name","grant_name", 6, "left", true);
			columnAttrList.push(columnAttr);
			
			columnAttr = new ColumnAttr("项目名称", "zh_title","zh_title", 7, "left", true);//表头，字段名，，，宽度比例，居左，是否需要表头排序
			columnAttrList.push(columnAttr);
			
			<security:authorize ifNotGranted="A_AUTH_DW">
			columnAttr = new ColumnAttr("申报单位", "org_name","org_name", 7, "left", true);//表头，字段名，，，宽度比例，居左，是否需要表头排序
			columnAttrList.push(columnAttr);
			</security:authorize>
			<security:authorize ifAnyGranted="A_AUTH_JHC">
			columnAttr = new ColumnAttr("主管处室", "admin_org_name","admin_org_name", 4, "center", true);
			columnAttrList.push(columnAttr);
			</security:authorize>
			/* <security:authorize ifAnyGranted="A_AUTH_SCS,A_AUTH_SCZJ,A_AUTH_SCZJSC,A_AUTH_SZ">
			columnAttr = new ColumnAttr("所在区市", "area_name","area_name", 3, "center", true);//表头，字段名，，，宽度比例，居左，是否需要表头排序
			columnAttrList.push(columnAttr);
			</security:authorize> */
			/* columnAttr = new ColumnAttr("项目类型", "proposal_type_name","proposal_type_name", 4, "center", true);//表头，字段名，，，宽度比例，居左，是否需要表头排序
			columnAttrList.push(columnAttr); */
			columnAttr = new ColumnAttr("项目负责人", "psn_name","psn_name", 5, "center", true);
			columnAttrList.push(columnAttr);
			
			
			
	/* 		columnAttr = new ColumnAttr("专题名称", "domain_name","domain_name", 5, "center", true);
			columnAttrList.push(columnAttr);
			
			columnAttr = new ColumnAttr("水印号", "prp_version","prp_version", 6, "left", true);
			columnAttrList.push(columnAttr); */
			
			columnAttr = new ColumnAttr("受理编号", "prp_no","prp_no", 6, "left", true);
			columnAttrList.push(columnAttr);
			
			columnAttr = new ColumnAttr("技术领域", "JS_NAME","JS_NAME", 6, "left", true);
			columnAttrList.push(columnAttr);
			
			/* columnAttr = new ColumnAttr("主管单位", "org_parent_name", "org_parent_name", 7,"center", true);
			columnAttrList.push(columnAttr); */
			columnAttr = new ColumnAttr("归口管理部门类型", "category", "category", 7,"center", true);
			columnAttrList.push(columnAttr);
			
			
			columnAttr = new ColumnAttr("归口管理部门", "off_name", "off_name", 7,"center", true);
			columnAttrList.push(columnAttr);
			
			columnAttr = new ColumnAttr("工作进度", "statusName", "status", 6,"center", true);
			columnAttrList.push(columnAttr);
			
			columnAttr = new ColumnAttr("审核意见", "comment", "comment", 4,"center", false,false,"text",false,1);
			columnAttrList.push(columnAttr);
			
			columnAttr = new ColumnAttr("PDF", "pdf", "pdf",4,"center", false,false,"text",false,1);
			columnAttrList.push(columnAttr);
			<security:authorize ifAnyGranted="ROLE_ADMINISTRATOR">
			columnAttr = new ColumnAttr("重置PDF", "reGenPdf", "reGenPdf", 3,"center", false,false,"text",false,1);
			columnAttrList.push(columnAttr);
			</security:authorize>
			
		//	columnAttr = new ColumnAttr("操作", "", "", 7,"center", false);
		//	columnAttrList.push(columnAttr);
			columnAttr = new ColumnAttr("status", "status", "status", 3,"left", false,false,"text",true,1);
			columnAttrList.push(columnAttr);
			columnAttr = new ColumnAttr("flagCan", "flagCan", "flagCan", 3,"left", false,false,"text",true,1);
			columnAttrList.push(columnAttr);
			columnAttr = new ColumnAttr("grantCode", "grantCode", "grantCode", 3,"left", false,false,"text",true,1);
			columnAttrList.push(columnAttr);
			columnAttr = new ColumnAttr("introPdfCode", "introPdfCode", "introPdfCode", 3,"left", false,false,"text",true,1);
			columnAttrList.push(columnAttr);

			irisGrid.setColumnAttrs(columnAttrList);
			
			 irisGrid.setToolsBar([
			                       {
			                           id : 'exportPrjDetailG',
			                           name : '导出项目信息',
			                           trigger : exportPrjDetail
			                       }  ,
			                       {
			                           id : 'exportPdf',
			                           name : '下载所选项目PDF',
			                           trigger : exportPdf
			                       },
			                       <security:authorize ifAnyGranted="A_AUTH_TJBM">
			                       
			                        {
			                           id : 'editEmailId',
			                           name : '修改邮件通知模板',
			                           trigger : editEmail
			                       }, 

			                       {
			                           id : 'noticeEmail',
			                           name : '发送邮件通知',
			                           trigger : function(gridObj, selectIdArray, recordRows) {//按钮onclick方法 grid本身 选中的行id 总行数
			                               var checkflag = true;

			                               var prpCodes = getSelOptPrpCode();

			                               prpCodes = prpCodes + "";
			                               var num = 0;
			                               var ps = prpCodes.split(",");
			                               if (selectIdArray.length > 0) {
			                                   for ( var i = 0; i < ps.length; i++) {

			                                       if ($("#isAcceptPdf_" + ps[i]).val() == 1) {
			                                           num = num + 1;
			                                       }
			                                   }
			                               }
			                               if (num > 0) {
			                                   scmError("你选择的项目中有" + num + "个项目已经接收纸质材料了，不需要再发邮件通知了，请先去除选择");
			                                   checkflag = false;
			                               }

			                               if (checkflag) {
			                            	   sendMessage("noticeEmail", gridObj, selectIdArray,recordRows);

			                           }
			                       }
			                       }, 
			                       {
                                       id : 'exportPrjCollects',
                                       name : '导出项目汇总表',
                                       trigger : exportPrjCollects
                                   }  ,
                                   {
                                       id : 'exportPrjCollectes',
                                       name : '导出推荐清单',
                                       trigger : exportPrjCollectes
                                   }
			                       </security:authorize>
			                       
			                       <security:authorize ifAnyGranted="A_AUTH_DW">

                                   {
                                       id : 'exportPrjCollectes',
                                       name : '导出推荐清单',
                                       trigger : exportPrjCollectes
                                   }
                                   
                                   </security:authorize>
			                       ]);
			
			irisGrid.setUrl("${ctx}/prpapprove/list-for-view");//查询url
			irisGrid.setCaption("暂写");
			irisGrid.setDefaultSortName("prp_no");//默认排序字段
			irisGrid.setDefaultSortorder("asc");
			irisGrid.setWidth(978);//整个表格宽度
			irisGrid.setCheckAble(true);//表格左边是否要复选框
			irisGrid.setShowRowIndex(true);//是否显示行号
			irisGrid.setCanExportExcel(true);
			irisGrid.setQueryBox('searchBt', <security:authorize ifNotGranted="A_AUTH_DW,A_AUTH_DEPT,,A_AUTH_TJBM">'prpApprove_search2_chushi'</security:authorize><security:authorize ifAnyGranted="A_AUTH_DW,A_AUTH_DEPT,,A_AUTH_TJBM">'prpApprove_search2'</security:authorize>, ["grant_code", "research_value", "domain_value"]);//查询条件 按钮名，查询条件function_key
			irisGrid.onSelectAll = function(selectid,isSelect){//全选事件
				checkSelect();
			}
			irisGrid.onSelectRow = function(selectid,isSelect){//选择事件	
				checkSelect();
			}
			irisGrid.setLoadComplete(function() {
				irisGrid.attendQuery = true;
				var searchString = irisGrid.preDealOnQuery()['searchString'];
				$("#searchString").val(searchString);
				/* $("#sortItem").val( irisGrid.getGridDom().jqGrid("getGridParam", 'sortname'));
				$("#sortType").val(irisGrid.getGridDom().jqGrid("getGridParam", 'sortorder'));
		        //当前显示多少条
		       	var length = $("#dataGrid").getDataIDs().length;
				if(length > 0){//当资助类别不为空且 当前页数据大于0时，显示按钮
					$("#exportPrjDetailG").show();
				} else {
					$("#exportPrjDetailG").hide();
				}  */
			});
			irisGrid.build();
		}
		jQuery(function() {
			setStatus();
			buildGrid();
			//$("div[class*='ui-jqgrid-bdiv']").css("overflow","hidden");
			 $("#TopBarMnt").css("width","971px");
			 /*$("#dataGrid_toppager").css("display","none");
			$("#dataBar").css("display","none");
			$("a[class*='HeaderButton']").click(function(){
				$("#dataGrid_toppager").css("display","none");
			}); */
			$("#cb_dataGrid").click(function(){
				var checked=$(this).attr("checked");
				if(checked=="checked"){
					$("#dataGrid").find("td input[type='checkbox']").attr("checked","checked");
					$("#dataGrid").find("tr[class*='jqgrow']").each(function(){
						if($(this).find("td input[type='checkbox']").length<=0){
							$(this).removeClass("ui-state-highlight");
						}
					});
					
				}else{
					$("#dataGrid").find("td input[type='checkbox']").attr("checked",false);
				}
			});
			var index = 0;
			var stat_year = "";
			$("dl[id='stat_year']").find("a[class='c_item_checked']").each(function(){
				stat_year = $(this).prev().val();
				index ++;
			});
			if(index > 1)
				stat_year = "0";
			$("#research,#research_img,#research_tree_img").unbind("click").removeAttr("onclick");
			$("#research,#research_img,#research_tree_img").bind("click",function(){
				
				show_research("research",{"locale":"zh_CN","key":"subject_researcharea_cri","cacheable":"false","sqlParamVal":"{'grant_code':'"+$("#grantCname_hideId").val()+"','stat_year':'"+stat_year+"'}"});
			});
			$("#domain,#domain_img,#domain_tree_img").unbind("click").removeAttr("onclick");
			$("#domain,#domain_img,#domain_tree_img").bind("click",function(){
				show_domain("domain",{"locale":"zh_CN","key":"domain1","cacheable":"false","sqlParamVal":"{'grant_code':'"+$("#grantCname_hideId").val()+"','stat_year':'"+stat_year+"','researchCode':'"+$("#research_hideId").val()+"'}"});
			});

		});
		

		//导出excel方法
		var exportPrjDetail = function() {
				var grantCode=$("#grant_code").val();
				if(grantCode=='916'){
					//科学技术奖导出
					 showReportKxjsjDialog();
				}else{
					var formObj = $("#exportExcel");
			        formObj.attr('action','${ctx}/prpapprove/export_excel');  
					formObj.submit();
				}
		};
		
		//导出excel方法
		//修改 增加  省科技重大专项 ws 20170621
		/* var exportPrjCollects = function() {
		   var formObj = $("#exportExcel");
		   var grantCode=$("#grant_code").val()
		   if (grantCode=='2' || grantCode=='4') {
			   formObj.attr('action','${ctx}/prpapprove/export_excel_collects');  
			   formObj.submit(); 
		  }else{
			  alert("目前该功能只能导出 创新型省份建设专项与省科技重大专项 的报表！！");
			  return false;
		  }
		   
		}; */
		
		//增加报表打印excel内容
		 var exportPrjCollects = function() {
			/* 获取了那一坨的数据 */
			var searchString = $("#searchString").val();
			
			if(!!!searchString) {
				scmWarn("请先选择申报年度，再导出！！目前该功能只能导出 创新型省份建设专项或省科技重大专项 的报表。");
	             return false;
	        } 
			
			var searchArray = searchString.split("[tear]");
	         
			var statYear = ""; // 申报年度
			
			var grantCode = "";
			  
			
			 for(var i=0; i<searchArray.length; i++) {
	                if(searchArray[i].indexOf("grant_code")>-1) {
	                	grantCode = searchArray[i].split(":")[1];
	                    break;
	                }
	            }
	            
	          if(!!!grantCode) {
	        	  scmWarn("请先选择项目类别再导出！！");
	                return false;
	           }
	        if(!makeTrueGrantCode(grantCode)) {
	        	scmWarn("请先选择创新型省份建设专项或省科技重大专项内或这2类计划类别下面的子类别！！");
	        	return false;
	         }  
			
            for(var i=0; i<searchArray.length; i++) {
                if(searchArray[i].indexOf("stat_year")>-1) {
                	statYear = searchArray[i].split(":")[1];
                    break;
                }
            }
            
            if(!!!statYear) {
            	scmWarn("请先选择申报年度再导出！！");
                return false;
           }
           
           var dataGridLength = $("#dataGrid").find("tr").length - 1;
           if(dataGridLength == 0){
        	   scmWarn("数据为空！！");
               return false;
           } 
		   
		   var url = "${ctx}/prpapprove/exportPrjCollectionView?searchString="+searchString+"&statYear=" + statYear + "&grantCode=" + grantCode;
	       window.open(url,'newwin','height=900,width=1200,top=100,left=150,scrollbars=yes,toolbar=no,menubar=no,titlebar=no,status=no,resizable=no,menubar=no');
		}; 
		
		
		function makeTrueGrantCode(grant_code){
			 var makeTrue = false ;
			 $.ajax({
				 type : 'post',
                 data : {"grantCode" : grant_code},
                 url : "${ctx}/prpapprove/prjCollectionMakeTrue",
                 async: false,
                 success : function(msg){
                     if(msg == "success"){
                     	/* scmSuccess(msg); */
                    	  makeTrue = true;
                     }else if(msg == "error"){
                          scmSuccess("请先选择创新型省份建设专项或省科技重大专项内或这2类计划类别下面的子类别");
                          makeTrue = false;
                     }
                     return makeTrue;
                 },
                 error : function() {
                     scmError("操作失败！");
                     prcWin.closeWin();
                 },
			 });
			 return makeTrue;
		}		 
		
		
		//导出excel方法
		var exportPrjCollectes = function() {
			 var grantCode=$("#grant_code").val();
			 var searchString = $("#searchString").val();
// 			 jQuery('#dataGrid').jqGrid('getGridParam','postData')['searchString'];
			 var searchArray = searchString.split("[tear]");
			 var statYearStr = "";
			
			 if (grantCode==null ||grantCode==''|| grantCode==undefined||grantCode=="") {
				   alert("请选择项目类别！！");
					  return false;
			  }else{
				  
				  for(var i=0;i<searchArray.length;i++) {
		                 if(searchArray[i].indexOf("stat_year")>-1) {
		                     statYearStr = searchArray[i].split(":")[1];
		                     break;
		                 }
		             }
				  if(!!!statYearStr) {
		                 alert("请选择具体的申报年度！！");
		                 return false;
		             }
		             if(statYearStr.split(",").length>1) {
		                 alert("请选择具体的申报年度！！");
		                 return false;
		             }
				  var s=$("#searchString").val();
					var grant_hideName=$("#grant_hideName").val();
					tb_show("推荐清单",ctx+'/prpapprove/recommendDetailedList?flag=init&searchString='+s+'&grant_hideName='+grant_hideName+'&TB_iframe=true&height=800&width=1000');
				    $(parent.document).find("#TB_ajaxWindowTitle").text("推荐清单");

				  
			  }
					  /*  var formObj = $("#exportExcel");
		   var grantCode=$("#grant_code").val()
		   if (grantCode=='2' || grantCode=='4') {
			   
		   }
		   formObj.attr('action','${ctx}/prpapprove/export_excel_collects?Reviews=all');  
		   formObj.submit();  */
		   
		};
		
		var getSelOpt = function() {
			var g = "";
			$("input:checkbox[id^='jqg_dataGrid_']").each(function(i, obj) {
				if (obj.checked) {
					g += "," + obj.id.replace("jqg_dataGrid_", "");
				}
			});
			if (g != "") {
				g = g.substring(1);
			}
			return g;
		};
		//打包下载pdf
		var exportPdf = function(){
            var keyCodes = getSelOpt();
            var count = keyCodes.split(",").length;
            if(count > 50){
                scmWarn("请不要选择超过50个项目！", null, 2000);
                return false;
            }
            if (keyCodes == "") {
                scmWarn("请选择要下载pdf的项目！", null, 2000);
                return false;
            }
            $.ajax({
                url:ctxpdf+"/pdf/validatePdfs",
                data:"keyCodes="+encodeURIComponent(keyCodes)+"&type=proposal",
                //dataType:"json",
                success:function(msg){
                    var obj = eval("(" + msg + ")");
                    if(obj!=null&&obj!=""){
                        if(obj.result=='error'){
                            var results='';
                            for (var i=0;i<obj.results.length;i++){
                                results=results+obj.results[i]+"<br/>";
                            }
                            //var results=obj.results+"";
                            scmError(results);
                            return;
                        }else if(obj.result=='success'){
                            scmSuccess("正在下载……请稍侯…");
                            var url = "${ctx}"+ "/proposal/getintrozip?type=pdf&keyCodeStr="+encodeURIComponent(keyCodes);
                            $("#ifile").attr("src",url);
                            return false;
                        }
                    }
                },
                error : function() {
                    scmError("PDF下载失败，请稍后下载！");
                }
            });
		}
		
		//批量下载简介表
		var exportIntro = function(){
			var keyCodes = getSelOpt();
			var flag  = getSelIntroPdfCode();
			if(!flag){
				scmWarn("您选择了没有简介表的项目，请重新选择！", null, 2000);
				return false;
			}
			if (keyCodes == "") {
				scmWarn("请选择要下载简介的项目！", null, 2000);
				return false;
			}
			scmSuccess("正在下载……请稍侯…",null,4000);
			location ="${ctx}"+ "/proposal/getintrozip?type=introPdf&keyCodeStr="+encodeURIComponent(keyCodes);
			return false;
		}
		
		
		
		var getSelIntroPdfCode = function(){
			var flag = true;
			$("input:checkbox[id^='jqg_dataGrid_']").each(function(i,obj){
				if(obj.checked){
					var introPdfCode = $(obj).parent().parent().find("input:hidden[id^='introPdfCode_']").val();
				  if(introPdfCode == "" || introPdfCode == null){
					  flag = false;
				  }
				}
			});
			return flag;
			
		}
		
		function setStatus(){
			if('${param.prpstatus}' != ''){
				$("#prpstatus option[value='${param.prpstatus}']").attr("selected","selected");
				//$("#prpstatus option[value='1']").attr("selected", "selected"); 
			}
		}
		/** 显示工作进度 */
		function showPrjProgress(keyCode,progressCode){
			var url = ctx + "/prpapprove/showPrjProgress";
			url = url + "?keyCodeStr="+keyCode+"&progressCode="+progressCode;
			url = url + "&TB_iframe=true&height=500&width=700";	
			tb_show("工作进度",url, false);
		}
		/**查看单位信息*/
		function orgInfoView(orgCode){
			//$("#orgCode").val(orgCode);
			//$("#mainForm").submit();
			tb_show("查看单位信息","${ctx}/orgmanage/verifyorg/org-info-view?orgCode=" + orgCode
					+ "&TB_iframe=true&height=460&width=950", false);
		}
		
		/* function showReportDialog(){
			var searchString=jQuery('#dataGrid').jqGrid('getGridParam','postData')['searchString'];
			if($("#grant_code").val() == '' || $("#grant_code").val()  == undefined)
			{
				tb_show("打印汇总表","${ctx}/prpapprove/list-for-report"+"?searchString="+encodeURIComponent(searchString)+"&TB_iframe=true&height=460&width=1024", false);
			}else{
				//先封装数据
				var urlStr = "";
				var criteria_key = $("#_dyn_panel").attr("functionkey");
				var queryTableObj = $("#" + criteria_key + " *[id='_dyn_panel']");
				var querySels = [];
				$("[id^='_dyn_criteria'][id$='_field']", queryTableObj).each(
						function() {
							querySels.push($(this).attr('id'));
						});
				var querySelIdCrowd = querySels;
				
				var queryKVStr = '';
				for ( var i = 0; i < querySelIdCrowd.length; i++) {
					var selId = querySelIdCrowd[i];
					var queryId = $("#"+criteria_key).find('#' + selId).val();
					var destContral = $("#"+criteria_key).find('#' + queryId, $('#' + selId).parent().next());
					var queryValue = destContral.val();
					var fieldname = destContral.attr("name");
					var queryCellValue = $.trim(queryValue);
					if(i != querySelIdCrowd.length-1){
						urlStr = urlStr +fieldname+":"+queryCellValue+"[tear]";
					}else{
						urlStr = urlStr +fieldname+":"+queryCellValue;
					}
				}			
				tb_show("打印汇总表","${ctx}/prpapprove/list-for-report1"+"?searchString="+encodeURIComponent(urlStr)+"&TB_iframe=true&height=460&width=1024", false);
				
			}
		}
		 */
		  function showReportKxjsjDialog(){
			 //得到页面查询条件
				var searchString=jQuery('#dataGrid').jqGrid('getGridParam','postData')['searchString'];
				if($("#grant_code").val() == '' || $("#grant_code").val()  == undefined)
				{
				 	alert("项目类别不能为空");	
				}else if($("#grant_code").val() !='916'){
					alert("请选择科学技术奖项目");	
				}else{
					//先封装数据
					//拼接查询条件的值,形如k,v;多个值之间使用[tear]隔开,当new一个PageHanlder的时候,会自动将值进行封装到ConditionContainer中
					var urlStr = "";
					var criteria_key = $("#_dyn_panel").attr("functionkey");
					var queryTableObj = $("#" + criteria_key + " *[id='_dyn_panel']");
					var querySels = [];
					$("[id^='_dyn_criteria'][id$='_field']", queryTableObj).each(
							function() {
								querySels.push($(this).attr('id'));
							});
					var querySelIdCrowd = querySels;
					
					var queryKVStr = '';
					for ( var i = 0; i < querySelIdCrowd.length; i++) {
						var selId = querySelIdCrowd[i];
						var queryId = $("#"+criteria_key).find('#' + selId).val();
						var destContral = $("#"+criteria_key).find('#' + queryId, $('#' + selId).parent().next());
						var queryValue = destContral.val();
						var fieldname = destContral.attr("name");
						var queryCellValue = $.trim(queryValue);
						if(i != querySelIdCrowd.length-1){
							urlStr = urlStr +fieldname+":"+queryCellValue+"[tear]";
						}else{
							urlStr = urlStr +fieldname+":"+queryCellValue;
						}
					}
					
				  var statYear=$("#stat_year").find("option:selected").text();
					
				  //type表示导出类型,与数据库表proposal_sl_report中的rpt_no对应,当type为空时默认设置为1,导出科学技术奖申请书信息时设置type为2
					tb_show("导出科学技术奖项目信息清单",ctx+"/prpapprove/list-for-report1-kxjsj?searchString="+encodeURIComponent(urlStr)+"&statYear="+statYear+"&rpt_no_type=2&TB_iframe=true&height=460&width=1024", false);
				
			}
		}
	 function initSubjectTreeValueExp2(treeId, treeNode) {
			if(treeId=="grant"){
		  		$("#research").val("");
				$("#research_hideId").val("");
				$("#research_hideName").val("");
				$("#researchCname_hideId").val("");
				$("#researchCname").val("");
				$("#research_value").val("");
				$("#domain").val("");
				$("#domain_hideId").val("");
				$("#domain_hideName").val("");
				$("#domainCname_hideId").val("");
				$("#domainCname").val("");
				$("#domain_value").val("");
				$("#grant_code").val(treeNode.id);
				$("#grantCnameKJ").val(treeNode.name);
		  	}else if(treeId=="research"){
		  		$("#domain").val("");
				$("#domain_hideId").val("");
				$("#domain_hideName").val("");
				$("#domainCname_hideId").val("");
				$("#domainCname").val("");
				$("#domain_value").val("");
		  		$("#research_value").val(treeNode.id);
		  	}else if(treeId=="domain"){
		  		$("#domain_value").val(treeNode.id);
		  	}
			$("#"+treeId).parents("td").find("[name$='"+treeId+"Cname_hideId'],[id$='"+treeId+"Cname_hideId']").val(treeNode.id);
			var str = treeNode.name;
			var obj = treeNode.parentNode;
			while (obj != null) {
				str = obj.name + "-" + str;
				obj = obj.parentNode;
			}
			$("#"+treeId).parents("td").find("[name$='"+treeId+"Cname'],[id$='"+treeId+"Cname']").val(str.substring(str.indexOf("-")+1));
		}
	//覆盖函数
		function initSubjectTreeValueExp(treeId, treeNode) {
		  	if(treeId=="grant"){
		  		$("#research").val("");
				$("#research_hideId").val("");
				$("#research_hideName").val("");
				$("#researchCname_hideId").val("");
				$("#researchCname").val("");
				$("#research_value").val("");
				$("#domain").val("");
				$("#domain_hideId").val("");
				$("#domain_hideName").val("");
				$("#domainCname_hideId").val("");
				$("#domainCname").val("");
				$("#domain_value").val("");
				$("#grant_code").val(treeNode.id);
		  	}else if(treeId=="research"){
		  		$("#domain").val("");
				$("#domain_hideId").val("");
				$("#domain_hideName").val("");
				$("#domainCname_hideId").val("");
				$("#domainCname").val("");
				$("#domain_value").val("");
		  		$("#research_value").val(treeNode.id);
		  	}else if(treeId=="domain"){
		  		$("#domain_value").val(treeNode.id);
		  	}
			$("#"+treeId).parents("td").find("[name$='"+treeId+"Cname_hideId'],[id$='"+treeId+"Cname_hideId']").val(treeNode.id);
			$("#"+treeId).parents("td").find("[name$='"+treeId+"Cname'],[id$='"+treeId+"Cname']").val(treeNode.name.substring(treeNode.name.indexOf(".")+1));
		}

//重现生成PDF
	function reGenPdf(keyCode, type, pdfCode){
		/*scmSuccess("正在下载……请稍侯…");
        location =ctx+ "/pdf/genpdf?keyCode="+encodeURIComponent(pos_code)+"&pdfCode="+encodeURIComponent(pdf_code)+"&type=proposal";*/
		if(!pdfCode){
			pdfCode = type;
			type='proposal';
		}
		$.ajax({
			url:ctxpdf+"/pdf/removePdfCode",
			data:"keyCode="+encodeURIComponent(keyCode)+"&pdfCode="+encodeURIComponent(pdfCode)+"&type="+encodeURIComponent(type),
			dataType:"text",
			success:function(msg){
				if(msg!=null&&msg!=""){
					if(msg=='warn'){
						scmWarn("上传的word文件正在转换成pdf，请稍后下载！");
					}else if(msg=='file_not_exist'){
						scmWarn("附件丢失,请联系管理员重新上传！");
					}else if(msg=='error'){
						scmError("PDF下载失败，请稍后下载！");
					}else if(msg=='overLoad'){
						scmWarn("当前是高峰期，由于PDF内容较多，生成速度较慢，请耐心等待！");
						// location =ctxpdf+ "/pdf/genpdf?keyCode="+encodeURIComponent(keyCode)+"&pdfCode="+encodeURIComponent(pdfCode)+"&type="+encodeURIComponent(type);
					}else if(msg=='success'){
						scmSuccess("正在下载……请稍侯…");
						location =ctxpdf+ "/pdf/genpdf?keyCode="+encodeURIComponent(keyCode)+"&pdfCode="+encodeURIComponent(pdfCode)+"&type="+encodeURIComponent(type);
					}
				}
			},
			error : function(msg) {
				scmError("PDF下载失败，请稍后下载！");
			}
		});
		return false;

	}
	 
	 
	</script>
</body>
</html>